package com.llly.controller;


import com.github.pagehelper.Page;
import com.llly.pojo.Easybuy_order;
import com.llly.pojo.Easybuy_order_detail;
import com.llly.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class OrderController {
    @Autowired
    private OrderService orderServer;





    public Page<Easybuy_order> showOrder(@RequestParam Integer userId,@RequestParam Integer PageIndex){
        Page<Easybuy_order> easybuyOrder = orderServer.showOrder(userId,PageIndex);

        easybuyOrder.getResult().forEach(System.out::println);
        return easybuyOrder;
    }
    //根据用户id查询订单
    @RequestMapping("/showOrder")
   public Map<String,Object> ShowOrder(Integer userId,Integer PageIndex){
        Page<Easybuy_order> page = showOrder(userId, PageIndex);

        page.getResult().forEach(System.out::println);
        Map map=new HashMap();
        map.put("pg",page.getResult());
        map.put("Total",page.getTotal());
        map.put("PageNum",page.getPageNum());
        map.put("Pages",page.getPages());
        return map;
    }
    //删除订单
    @RequestMapping("/delOrder")
    public Integer delOrder(@RequestParam String serialNumber){
        int i = orderServer.delOrder(serialNumber);
        return i;
    }

    //删除全部
    @RequestMapping("/delAllOrder")
    public int delAllOrder(@RequestParam String loginName){
        int a = orderServer.delAllOrder(loginName);
        return a;
    }
    @RequestMapping("/addOrder")
    public int addOrder(@RequestBody Easybuy_order easybuy_order) {
        return orderServer.addOrder(easybuy_order);
    }

    @RequestMapping("/addOrderDetail")
    public int addOrderDetail(@RequestBody  Easybuy_order_detail easybuy_order_detail) {
        return orderServer.addOrderDetail(easybuy_order_detail);
    }




}
